package com.UI
{
	import com.*;
	import com.Home.*;
	import com.Engine.*;
	import com.Packet.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.external.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.system.*;
	import flash.text.*;
	import flash.ui.*;
	import flash.utils.*;
	
	import org.aswing.*;
	import org.aswing.border.*;
	import org.aswing.border.EmptyBorder;
	import org.aswing.colorchooser.*;
	import org.aswing.dnd.*;
	import org.aswing.event.*;
	import org.aswing.ext.*;
	import org.aswing.geom.*;
	import org.aswing.tree.AbstractLayoutCache;
	
	public class FrameClickChar extends JFrame
	{
		//members define
		private var btn_chat:JLabelButton;
		private var btn_trade:JLabelButton;
		private var btn_stall:JLabelButton;
		private var btn_watch:JLabelButton;
		private var btn_team:JLabelButton;
		private var btn_team_leader:JLabelButton;
		private var btn_friend:JLabelButton;
		private var btn_home:JLabelButton;
		private var btn_close:JLabelButton;
		
		public function FrameClickChar()
		{
			setResizable(false);
			setClosable(false);
			setDragable(false);
			setBackgroundDecorator(null);
			this.setTitleBar(null);
			//this.getTitleBar().setTitleEnabled(false);
			//this.getTitleBar().setMinimizeHeight(0);
			//setBorder(new EmptyBorder());
			
			//component creation
			/*setOpaque(true);
			setForeground(new ASColor(0x0e3c3b, 1));
			setBackground(new ASColor(0x0e3c3b, 1));
			setSize(new IntDimension(60, 128));
			setPreferredSize(new IntDimension(60, 128));
			var border0:LineBorder = new LineBorder();
			border0.setColor(new ASColor(0x000000, 1));
			border0.setThickness(1);
			border0.setRound(0);
			setBorder(border0);
			var layout1:GridLayout = new GridLayout();
			layout1.setRows(8);
			layout1.setColumns(1);
			layout1.setHgap(0);
			layout1.setVgap(0);
			getContentPane().setLayout(layout1);*/
			
			//component creation
			getContentPane().setOpaque(true);
			getContentPane().setForeground(new ASColor(0x3399cc, 1));
			getContentPane().setBackground(new ASColor(0x3399cc, 1));
			setSize(new IntDimension(80, 150));
			setPreferredSize(new IntDimension(80, 150));
			var border0:LineBorder = new LineBorder();
			border0.setInterior(null);
			border0.setColor(new ASColor(0x0, 1));
			border0.setThickness(1);
			border0.setRound(0);
			getContentPane().setBorder(border0);
			var layout1:GridLayout = new GridLayout();
			layout1.setRows(9);
			layout1.setColumns(1);
			layout1.setHgap(0);
			layout1.setVgap(0);
			getContentPane().setLayout(layout1);
			
			btn_chat = new JLabelButton();
			btn_chat.setOpaque(false);
			btn_chat.setLocation(new IntPoint(1, 1));
			btn_chat.setSize(new IntDimension(26, 17));
			btn_chat.setText("聊天");
			
			btn_trade = new JLabelButton();
			btn_trade.setOpaque(false);
			btn_trade.setLocation(new IntPoint(5, 5));
			btn_trade.setSize(new IntDimension(58, 15));
			btn_trade.setText("交易");
			
			btn_stall = new JLabelButton();
			btn_stall.setLocation(new IntPoint(1, 31));
			btn_stall.setSize(new IntDimension(58, 15));
			btn_stall.setText("摊位");
			
			btn_watch = new JLabelButton();
			btn_watch.setOpaque(false);
			btn_watch.setLocation(new IntPoint(1, 46));
			btn_watch.setSize(new IntDimension(26, 17));
			btn_watch.setText("查看");
			
			btn_team = new JLabelButton();
			btn_team.setOpaque(false);
			btn_team.setLocation(new IntPoint(36, 5));
			btn_team.setSize(new IntDimension(26, 17));
			btn_team.setText("邀请组队");
			
			btn_team_leader = new JLabelButton();
			btn_team_leader.setOpaque(false);
			btn_team_leader.setLocation(new IntPoint(0, 28));
			btn_team_leader.setSize(new IntDimension(80, 14));
			btn_team_leader.setText("申请入队");
			
			btn_friend = new JLabelButton();
			btn_friend.setOpaque(false);
			btn_friend.setLocation(new IntPoint(67, 5));
			btn_friend.setSize(new IntDimension(26, 17));
			btn_friend.setText("加为好友");
			
			btn_home = new JLabelButton();
			btn_home.setOpaque(false);
			btn_home.setLocation(new IntPoint(160, 5));
			btn_home.setSize(new IntDimension(26, 17));
			btn_home.setText("访问幻境");
			
			btn_close = new JLabelButton();
			btn_close.setOpaque(false);
			btn_close.setLocation(new IntPoint(191, 5));
			btn_close.setSize(new IntDimension(26, 17));
			btn_close.setText("关闭");
			
			//component layoution
			getContentPane().append(btn_chat);
			getContentPane().append(btn_trade);
			getContentPane().append(btn_stall);
			getContentPane().append(btn_watch);
			getContentPane().append(btn_team);
			getContentPane().append(btn_team_leader);
			getContentPane().append(btn_friend);
			getContentPane().append(btn_home);
			getContentPane().append(btn_close);
			
			//----------------------------
			
			btn_trade.setForeground(ASColor.WHITE);
			btn_trade.setRollOverColor(ASColor.YELLOW);
			btn_trade.setPressedColor(ASColor.BLUE);
			btn_trade.setBackground(ASColor.GRAY);
			btn_stall.setForeground(ASColor.WHITE);
			btn_stall.setRollOverColor(ASColor.YELLOW);
			btn_stall.setPressedColor(ASColor.BLUE);
			btn_stall.setBackground(ASColor.GRAY);
			btn_team.setForeground(ASColor.WHITE);
			btn_team.setRollOverColor(ASColor.YELLOW);
			btn_team.setPressedColor(ASColor.BLUE);
			btn_team.setBackground(ASColor.GRAY);
			btn_team_leader.setForeground(ASColor.WHITE);
			btn_team_leader.setRollOverColor(ASColor.YELLOW);
			btn_team_leader.setPressedColor(ASColor.BLUE);
			btn_team_leader.setBackground(ASColor.GRAY);
			
			btn_friend.setForeground(ASColor.WHITE);
			btn_friend.setRollOverColor(ASColor.YELLOW);
			btn_friend.setPressedColor(ASColor.BLUE);
			btn_friend.setBackground(ASColor.GRAY);
			btn_chat.setForeground(ASColor.WHITE);
			btn_chat.setRollOverColor(ASColor.YELLOW);
			btn_chat.setPressedColor(ASColor.BLUE);
			btn_chat.setBackground(ASColor.GRAY);
			btn_watch.setForeground(ASColor.WHITE);
			btn_watch.setRollOverColor(ASColor.YELLOW);
			btn_watch.setPressedColor(ASColor.BLUE);
			btn_watch.setBackground(ASColor.GRAY);
			btn_home.setForeground(ASColor.WHITE);
			btn_home.setRollOverColor(ASColor.YELLOW);
			btn_home.setPressedColor(ASColor.BLUE);
			btn_home.setBackground(ASColor.GRAY);
			btn_close.setForeground(ASColor.WHITE);
			btn_close.setRollOverColor(ASColor.YELLOW);
			btn_close.setPressedColor(ASColor.BLUE);
			btn_close.setBackground(ASColor.GRAY);
			
			setBackgroundDecorator(new SolidBackground(new ASColor(0x0e3c3b,1.0)));
			btn_close.addActionListener(onBtnClose);
			
			btn_trade.addActionListener(onBtnTrade);
			btn_team.addActionListener(onBtnTeam);
			btn_team_leader.addActionListener(onBtnTeam);
			btn_chat.addActionListener(onBtnChat);
			btn_stall.addActionListener(onBtnStall);
			btn_friend.addActionListener(onBtnFriend);	
			btn_watch.addActionListener(onBtnWatch);	
			btn_home.addActionListener(onBtnHome);
			this.setClipMasked(false);
			getContentPane().setClipMasked(false);
		}
		private function onBtnClose(e:Event):void
		{
			//this.closeReleased();
			hide();
		}
		
		private function onBtnTeam(e:Event):void
		{
			if(_destCharId == CharInfo.charId)
				return;
			
			this.closeReleased();
			//PanelMain.showInfoTimeLimit("邀请组队请求发送成功!");
			if(!CharInfo.objSelf.isInTeam() || CharInfo.objSelf.isTeamLeader())
				Client.getInstance().sendPacketLogic(200,[_destCharId]);
			else if(!CharInfo.objSelf.isInTeam())
				Client.getInstance().sendPacketLogic(205,[_destCharId]);
		}
		
		private function onBtnTrade(e:Event):void
		{
			if(_destCharId == CharInfo.charId)
				return;
			this.closeReleased();
			Client.getInstance().sendPacketLogic(800,[_destCharId]);
		}
		private function onBtnStall(e:Event):void
		{
			//if(_destCharId == CharInfo.charId)
			//	return;
			this.closeReleased();
			Client.getInstance().sendPacketLogic(2100,[_destCharId]);
			FrameStall.nWatchCharId = _destCharId;
		}
		public static var _destCharId:int = 0;
		public static var _objDest:Object = null;
		private function onBtnFriend(e:Event):void
		{
			Client.getInstance().sendPacketLogic(601,[_destCharId]);
			this.closeReleased();
		}
		private function onBtnWatch(e:Event):void
		{
			Client.getInstance().sendPacketLogic(605,[int(_destCharId)]);
			this.closeReleased();
		}
		private function onBtnChat(e:Event):void
		{
			if(_objDest == null)
				return;
			FrameFriendChat.show(_objDest);
			this.closeReleased();
		}
		
		private function onBtnHome(e:Event):void
		{
			this.closeReleased();
			Home.visitHome(_destCharId);
		}
		
		public static var _frame:FrameClickChar = null;
		public static function show(container:Container,x:int,y:int,bTop:Boolean = true):void
		{
			if(_frame == null)
			{
				_frame = new FrameClickChar();
			}
			_frame.show();
			if(!container.contains(_frame))
				container.addChild(_frame);
			container.bringToTop(_frame);
			//_frame.pack();
			//_frame.setResizable(false);
			if(bTop)
				y -= _frame.height;
			if(y + _frame.height > container.height)
				y = container.height - _frame.height;
			if(x + _frame.width > container.width)
				x = container.width - _frame.width;
			_frame.setLocationXY(x, y);
			_frame.update();
			
		}
		public function update():void
		{
			btn_trade.setEnabled(_destCharId != CharInfo.charId);
			btn_team.setEnabled(_destCharId != CharInfo.charId);
			btn_team_leader.setEnabled(_destCharId != CharInfo.charId);
			btn_friend.setEnabled(_destCharId != CharInfo.charId);
			btn_chat.setEnabled(_destCharId != CharInfo.charId);
		}
		public static function hide():void
		{
			if(isShowing())_frame.hide();
		}
		public static function isShowing():Boolean
		{
			return(_frame != null&& _frame.isShowing());
		}
	}
}